package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmailService;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper mapper;

    @Override
    public EmployeeBean login(String account, String password) {
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();
        qw.eq("e_account", account);
        qw.eq("e_password", password);
        return mapper.selectOne(qw);
    }

    @Override
    public List<EmployeeBean> findByIdArray(Integer[] emIdArray) {

          List<Integer> list = Arrays.asList(emIdArray);

        return mapper.selectBatchIds(list);
    }

    @Override
    public IPage<EmployeeBean> cutByItem(Integer pageNO, String name, String dept) {
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();

        if (name != null && !"".equals(name)) {
            qw.like("e_realName", name);
        }
        if (dept != null && !"".equals(dept))
            qw.like("e_dept", dept);

        return mapper.selectPage(new Page<>(pageNO, 3), qw);
    }
}
